feat: simplify raid submission - #45
Conversation
- make target_id optional in table column - check reply is actually owned by raider - update related tests
n13
left a comment
There was a problem hiding this comment.
Code Review: Feat - Simplify Raid Submission
The implementation looks solid and adheres to the project's structure. The use of existing repositories and helper functions like parse_x_status_url keeps the code DRY.
I have a few suggestions to improve performance and robustness, specifically within handle_create_raid_submission.
1. Optimization: Check "Active Raid" First
In src/handlers/raid_quest.rs, the handler currently parses the target link and queries the relevant_tweets table before checking if there is an active raid.
If no raid is active, we should fail immediately to avoid unnecessary parsing and database lookups.
Recommendation: Move the active raid check to the top of the handler.
// Move this check to the start of handle_create_raid_submission
let Some(current_active_raid) = state.db.raid_quests.find_active().await? else {
return Err(AppError::Database(DbError::RecordNotFound(format!(
"No active raid is found"
))));
};2. Check User Association Early
Similar to the active raid check, verifying the user's X association can be done earlier. If the user isn't linked, we don't need to parse URLs or look up the target tweet.
Proposed Order of Operations:
- Check Active Raid (System availability)
- Check X Association (User eligibility)
- Parse & Validate Links (Input validation)
- Check Target Tweet (Business logic)
- Create Submission
3. Idempotency Handling
The creation of a raid submission uses the tweet ID as the primary key. If a user submits the same reply twice (e.g., due to a network retry), this will likely throw a generic database error (Unique Constraint Violation).
Suggestion: Consider handling the unique violation explicitly. Returning a 409 Conflict would be more descriptive for the frontend than a generic 500 or database error.
NoteI let it fix the DRY violoation PR 45: Simplify Raid Submission - Code ReviewSummaryThe changes successfully implement the simplification of raid submissions by decoupling the submission from a specific target tweet. The Changes AnalysisDatabase Schema
Backend Logic (
|
Summary
Now user need only to input one data. More check to ensure valid owner of reply tweet.
Changes